package cre.tomcat7.util;

import cre.tomcat7.ch03.Constants;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

/**
 * @Author penglai
 * @Date 2017/1/27.
 */
public class LoaderUtils {

    public static ClassLoader gainClassLoader(){
        URL[] urls = new URL[1];
        File webapp = new File(Constants.CLASS_PATH);
        URL url = null;
        try {
            url = new URL("file", null, webapp.getAbsolutePath() + File.separator);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        urls[0] = url;
        URLClassLoader classLoader = new URLClassLoader(urls);
        return classLoader;
    }
}
